package com.tougutips.like.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.controller.BaseController;
import com.tougutips.common.like.vo.LikeMeVo;
import com.tougutips.common.like.vo.LikeVO;
import com.tougutips.common.like.vo.UserLikesVo;
import com.tougutips.like.service.LikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/like")
@CrossOrigin
public class LikeController extends BaseController {

    @Autowired
    private LikeService likeService;

    @PostMapping("/like")
    public R Like(@RequestBody LikeVO userLike) {
        likeService.like(userLike);
        return R.ok(null, "点赞成功");
    }


    /**
     * 根据用户ID获取用户点赞记录
     * @author 张治怡
     * @date 2022/7/25 16:49
     * @param userid 用户ID
     * @return com.ruoyi.common.core.domain.R
     */
    @GetMapping("/getLikes/{userid}")
    public R getLikes(@PathVariable long userid){
       return R.ok(likeService.getLikes(userid));
    }

    /**
     * 根据用户ID查询被赞列表
     * @author 张治怡
     * @date 2022/7/26 16:40
     * @param userid
     * @return com.ruoyi.common.core.domain.R
     */
    @GetMapping("/getLikeMe/{userid}")
    public R getLikeMe(@PathVariable long userid){
        List<LikeMeVo> likeMe = likeService.getLikeMe(userid);
        return R.ok(likeMe);
    }

    //根据作品ID和类型来查询有多少个赞
    @GetMapping("/getProLike/{id}/{type}")
    public R getProLike(@PathVariable("id") long id,@PathVariable("type") int type){
        int likeNum =  likeService.getProLike(id,type);
        return R.ok(likeNum);
    }

    //取消点赞接口
    @PostMapping("/nolike")
    public R noLike (@RequestBody LikeVO userLike){
        likeService.noLike(userLike);
        return R.ok();
    }
}
